//
//  userFriendsModel.swift
//  weibo1
//
//  Created by 李进 on 15/10/20.
//  Copyright © 2015年 李进. All rights reserved.
//

import UIKit

class userFriendesModel: NSObject {
    
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    /// 用户模型
    var user: userModel?
    /// 缩放图片的url
    var pic_urls:[[String : String]]?
    /// 被转发的原微博信息字段
    var retweeted_status: userFriendesModel?

    
    init(dict:[String:AnyObject]){
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        
        
        // 判断 key 是否是 user,是的话就字典转模型
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                
                user = userModel(dict: dict)
            }
            return
        }
        // 判断 key 是否是 retweeted_status
        if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = userFriendesModel(dict: dict)
            }
            return
        }
        
        
        super.setValue(value, forKey: key)
        
    }
    
    
    /// 重写这个方法，可以动态字典转模型
    ///
    /// - parameter value: 值
    /// - parameter key:   key
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        let keys = ["id", "text", "created_at", "source", "user","pic_urls"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
